package com.itheima.test;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.itheima.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.SQLException;

public class test1 {
    @Test
    public void test(){
        //1 创建Spring核心对象
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2 从容器中根据id值获取对象
        UserService userService=ac.getBean("userService",UserService.class);

        //3 调用对象的方法
        userService.save();


    }
    @Test
    public void test1() throws SQLException {
        //1 创建Spring核心对象
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2 从容器中根据id值获取对象
        DruidDataSource source = ac.getBean("dataSource", DruidDataSource.class);
        //从连接池中获取连接
        DruidPooledConnection connection = source.getConnection();
        System.out.println(connection);
    }

}
